import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)
//引入封装好的模块
import menu from './modules/menu'
import user from './modules/user'
import role from './modules/role'
import cate from './modules/cate'
import specs from './modules/specs'
import goods from './modules/goods'
import banner from './modules/banner'
import member from './modules/member'
import seck from './modules/seck'
export default new Vuex.Store({
  state: {
    //登录之后的用户信息
    userInfo:sessionStorage.getItem('userinfo')? JSON.parse(sessionStorage.getItem('userinfo')) :null
  },
  getters:{
    getUserInfo(state){
      return state.userInfo
    }
  },
  mutations: {
      REQ_USERINFO(state,payload){
        if(payload){
            state.userInfo = payload
            sessionStorage.setItem('userinfo',JSON.stringify(payload))
        }else{
          sessionStorage.removeItem('userinfo')
        }

      }
  },
  actions: {
    changeUserAction({commit},payload){
      commit('REQ_USERINFO',payload)
    }
  },
  modules: {
    menu,
    user,
    role,
    cate,
    specs,
    goods,
    banner,
    member,
    seck
  }
})
